Skip to content

Conversation

@rachelmcr
Copy link
Contributor

@rachelmcr rachelmcr commented Nov 23, 2022

Part of: #8149

Description

When we format the delta percentage to display on an Analytics card (e.g. +36% or -16%) we also need to keep track of the direction of change (positive, negative, or zero). This PR updates the stats data formatter so it returns both the formatted string and direction of change for a stats delta percentage.

It also includes a couple small fixes to the calculations.

Changes

  • Adds a DeltaPercentage struct to represent the formatted string and direction of change, and returns that (instead of just a String) from the corresponding formatter methods.
  • Fixes the delta calculations:
    • If the previous and current values are both 0, the delta percentage is +0% (previously it was incorrectly returning +100%).
    • If the previous value was 0 and the current value is negative, the delta percentage is -100% (previously it was returning +100%).
  • Adds/updates unit tests.

Testing

These delta percentages aren't yet used in the app; confirm the unit tests are checking the correct values and tests pass.

Submitter Checklist

Update release notes:

  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

@rachelmcr rachelmcr added the feature: stats Related to stats, including Top Performers. label Nov 23, 2022
@rachelmcr rachelmcr added this to the 11.4 milestone Nov 23, 2022
@rachelmcr rachelmcr marked this pull request as ready for review November 23, 2022 20:36
@peril-woocommerce
Copy link

Warnings
⚠️ This PR is assigned to a milestone which is closing in less than 2 days Please, make sure to get it merged by then or assign it to a later expiring milestone

Generated by 🚫 dangerJS

Copy link
Contributor

@Ecarrion Ecarrion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good to me, simpler and easy to read! Good Job!

Base automatically changed from issue/8149-delta-percentage-helper to trunk November 24, 2022 00:12
@rachelmcr rachelmcr enabled auto-merge November 24, 2022 00:13
@wpmobilebot
Copy link
Collaborator

You can test the changes from this Pull Request by:
  • Clicking here or scanning the QR code below to access App Center
  • Then installing the build number pr8202-1dc6560 on your iPhone

If you need access to App Center, please ask a maintainer to add you.

@rachelmcr rachelmcr merged commit 58d4a51 into trunk Nov 24, 2022
@rachelmcr rachelmcr deleted the issue/8149-delta-percentage-value branch November 24, 2022 14:48
@rachelmcr rachelmcr linked an issue Dec 5, 2022 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature: stats Related to stats, including Top Performers.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Analytics Hub] Configure Orders Analytics card

4 participants